require(['init'], function () {
    //获取当前的id
    var taskid = location.search.urlToObj().taskid;
    var classe=location.search.urlToObj().classe;
    var userid="",currentid="";
    var type = location.search.urlToObj().type
    var classeid = location.search.urlToObj().classeid;
    $('.navname').attr('href','./teacher_class_lesson.html?type='+type+'&classeid='+classeid+'&classe='+classe+'')
    $.ajax({
        url: ' /api/user/current',
        type: 'get',
        async:false,
        success:function(data){
            userid = data.data.userid;

        }
    });
    $.ajax({
        url: '/api/teacher/user/' + userid,
        type: 'get',
        async:false,
        success:function(json){
            currentid = json.data.teacheruid //当前老师的id
        }
    })
    function getstudentjob() {
        $.ajax({
            url:"/api/task/subject/"+taskid+"/status",
            type:"get",
            success:function(json){
                $('.lessonname').html(json.data.schedule);
                $('.classname').html(classe);
                var  $subject_one=$('.subject_one').html("");
                $('<dl>\
           <dt>'+i18next.t('job.students')+'</dt>\
           <dd>'+json.data.students+'</dd>\
         </dl>\
         <dl>\
           <dt>'+i18next.t('job.assignments')+'</dt>\
           <dd>'+json.data.replys+'</dd>\
         </dl>\
         <dl>\
            <dt>'+i18next.t('job.noassignments')+'</dt>\
           <dd>'+json.data.unreplys+'</dd>\
         </dl>\
         <dl style="border-right:none">\
       <dt>'+i18next.t('job.completion')+'</dt>\
           <dd>'+(json.data.persent==0?"0":json.data.persent+"%")+'</dd>\
          <dl>').appendTo($subject_one);

            }

        })

        $.ajax({
            url: '/api/task/subject/'+taskid+'/commits',
            type:'get',
            success: function (data) {
                console.log(data)
                var $listTable = $('#jos_list').html('');
                $thead=$('<thead class="thead">\
                <tr>\
                  <th>'+i18next.t('table.no')+'</th>\
                  <th>'+i18next.t('job.assignments')+'</th>\
                  <th>'+i18next.t('table.jobstatus')+'</th>\
                  <th>'+i18next.t('table.subjob')+'</th>\
                <th>'+i18next.t('table.handle')+'</th>\
                </tr>\
              </thead>').appendTo($listTable)
                var $tbody=$('<tbody></tbody>').appendTo($listTable)
                $.each(data.data,function(index,item){
                    var $tr=$('<tr class="enroll"></tr>').appendTo($tbody);
                    var replyat="";
                    if(item.replyat==""){
                        return "--";
                    }else{
                        var replyat=$.toDate(item.replyat).Format('YYYY-MM-DD hh:mm:ss')
                    }
                    $tr.append('<td>'+(index+1)+'</td>');
                    $tr.append('<td>'+item.student+'</td>');
                    var $replyed=$('<td></td>').appendTo($tr);
                    $tr.append('<td>'+replyat+'</td>');
                    var $operation=$('<td></td>').appendTo($tr);
                    if(item.replyed==1){
                        var $completed=$('<a>'+i18next.t('job.done')+'已完成</a>').appendTo($replyed);
                        $completed.parent().parent().addClass("completed");
                        $('<a class="btn btn-primary btn-sm btn-inverse" href="corrects_job.html?replyid='+item.replyid+'&taskid='+taskid+'&studentuid='+item.studentuid+'&studentname='+item.student+'&classe='+classe+'">'+i18next.t('table.homeworkcorrecting')+'</a>').appendTo($operation);
                    }else {
                        var $complete=$('<a style="color:red">'+i18next.t('job.undone')+'</a>').appendTo($replyed);
                        $complete.parent().parent().addClass("complete");
                        $('<a style="color:red">'+i18next.t('job.notsub')+'</a>').appendTo($operation);
                    }
                })
                $(".all").on('click',function(){
                    $(this).addClass("hover")
                    $('.completed').removeClass('hover');
                    $('.complete').removeClass('hover');
                    $listTable.find('.enroll').show();
                    $('.thead').find('tr').show();
                })
                $(".completed").on('click',function(){
                    $(this).addClass("hover")
                    $('.all').removeClass('hover');
                    $('.complete').removeClass('hover');
                    $listTable.find('.enroll').show()
                    $listTable.find('tr:not(.completed)').hide();
                    $('.thead').find('tr').show();
                })
                $(".complete").on('click',function(){
                    $(this).addClass("hover")
                    $('.all').removeClass('hover');
                    $('.completed').removeClass('hover');
                    $listTable.find('.enroll').show()
                    $listTable.find('tr:not(.complete)').hide();
                    $('.thead').find('tr').show();
                })

            }
        })
    }
    getstudentjob();
})
